package com.season.order.listener;

import com.alibaba.fastjson.JSON;
import com.reason.order.pojo.Order;
import com.season.order.config.RabbitMqConfig;
import com.season.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 陈正果
 * @date 2020/6/30 15:22
 */
@Component
public class OrderListener {
    @Autowired
    private OrderService orderService;

    /**
     * 监听订单创建队列
     *
     * @param message order类json
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_ORDER_CREATE)
    public void orderCreate(String message) {
        Order order = JSON.parseObject(message, Order.class);
        orderService.insertOrder(order);
    }

    /**
     * 监听订单支付成功队列
     *
     * @param message order类json
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_ORDER_SUCCESS)
    public void orderSuccess(String message) {
        Order order = JSON.parseObject(message, Order.class);
        orderService.updateOrder(order);
    }
}
